package cn.com.blueInfo.bpm.person.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.person.request.GroupUserDTO;
import cn.com.blueInfo.bpm.person.response.GroupUserVO;
import cn.com.blueInfo.bpm.person.service.GroupUserService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 群组固定人员表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:52
 */
@Tag(name = "群组固定人员 接口")
@RestController
@RequestMapping("/person/groupUser")
public class GroupUserController extends BaseController {

    @Autowired
    private GroupUserService groupUserService;

    /**
     * 新建群组固定人员
     * @param groupUserDTO 群组固定人员参数
     * @return ResultInfo
     */
    @Operation(summary = "新增群组固定人员")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createGroupUser(
            @Validated({Create.class, Default.class}) @RequestBody GroupUserDTO groupUserDTO) {
        return groupUserService.addGroupUser(groupUserDTO);
    }

    /**
     * 批量新建群组固定人员
     * @param groupUserDTOList 群组固定人员参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建群组固定人员")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateGroupUser(
            @Validated({Create.class, Default.class}) @RequestBody List<GroupUserDTO> groupUserDTOList) {
        return groupUserService.batchAddGroupUser(groupUserDTOList);
    }

    /**
     * 根据ID删除群组固定人员
     * @param groupUserId 群组固定人员ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除群组固定人员")
    @DeleteMapping("/removeInfo/{groupUserId}")
    public ResultInfo<Integer> deleteGroupUserById(
            @Parameter(name = "ID") @PathVariable Long groupUserId) {
        return groupUserService.removeGroupUser(groupUserId);
    }

    /**
     * 批量根据ID删除群组固定人员
     * @param groupUserIdList 群组固定人员ID列表
     * @return ResultInfo
     */
    @Operation(summary = "批量根据ID删除群组固定人员")
    @DeleteMapping("/removeInfoList/{groupUserIdList}")
    public ResultInfo<Integer> batchDeleteGroupUserById(
            @Parameter(name = "ID") @PathVariable List<Long> groupUserIdList) {
        return groupUserService.batchRemoveGroupUser(groupUserIdList);
    }

    /**
     * 根据ID全量更新群组固定人员
     * @param groupUserId 群组固定人员ID
     * @param groupUserDTO 群组固定人员参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新群组固定人员")
    @PutMapping("/modifyInfo/{groupUserId}")
    public ResultInfo<Integer> updateGroupUserFull(
            @Parameter(name = "ID") @PathVariable Long groupUserId,
            @Validated({Update.class, Default.class}) @RequestBody GroupUserDTO groupUserDTO) {
        validateUpdateId(groupUserId, groupUserDTO.getId());
        return groupUserService.modifyGroupUser(groupUserDTO);
    }

    /**
     * 根据ID部分更新群组固定人员
     * @param groupUserId 群组固定人员ID
     * @param groupUserUpdatePartialDTO 群组固定人员参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新群组固定人员")
    @PatchMapping("/modifyPartialInfo/{groupUserId}")
    public ResultInfo<Integer> updateGroupUserPartial(
            @Parameter(name = "ID") @PathVariable Long groupUserId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            GroupUserDTO.UpdatePartialDTO groupUserUpdatePartialDTO) {
        validateUpdateId(groupUserId, groupUserUpdatePartialDTO.getId());
        return groupUserService.modifyGroupUserPartial(groupUserUpdatePartialDTO);
    }

    /**
     * 根据ID查询群组固定人员
     * @param groupUserId 群组固定人员ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询群组固定人员")
    @GetMapping("/getInfo/{groupUserId}")
    public ResultInfo<GroupUserVO> getGroupUserById(
            @Parameter(name = "ID") @PathVariable Long groupUserId) {
        return groupUserService.queryGroupUserById(groupUserId);
    }

    /**
     * 分页查询群组固定人员
     * @param groupUserQueryDTO 群组固定人员参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询群组固定人员")
    @GetMapping("/getInfos")
    public ResultInfo<Page<GroupUserVO>> getGroupUserPage(
            @Validated GroupUserDTO.QueryDTO groupUserQueryDTO) {
        return groupUserService.queryGroupUserPage(groupUserQueryDTO);
    }

    /**
     * 根据条件查询群组固定人员
     * @param groupUserQueryDTO 群组固定人员参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询群组固定人员")
    @GetMapping("/getInfoList")
    public ResultInfo<List<GroupUserVO>> getGroupUserList(
            @Validated GroupUserDTO.QueryDTO groupUserQueryDTO) {
        return groupUserService.queryGroupUserList(groupUserQueryDTO);
    }

}
